﻿using ShortcutMenu.Hooks;
using ShortcutMenu.Manager;
using ShortcutMenu.Render;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ShortcutMenu
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private MenuApplication _menuApplication;

        public MainWindow()
        {
            InitializeComponent();

            _menuApplication = new MenuApplication(this);

            //进入隐藏状态
            this.Opacity = 0;
            this.Hide();

            Console.WriteLine("加载完成");

            MenuApplication.GetManager<ReaderManager>().ShowWindow<DesktopRender>();
        }



        private void MainWindows_Closing(object sender, CancelEventArgs e)
        {
            MenuApplication.GetManager<HookManager>().HookStopAll();//卸载所有钩子
        }

        /// <summary>
        /// 窗口隐藏事件
        /// </summary>
        private void WindowClone_Click(object sender, MouseButtonEventArgs e)
        {
            MenuApplication.GetManager<ReaderManager>().HideCurWindow();
        }



        //private void but01_Add(object sender, RoutedEventArgs e)
        //{
        //    var name = DataName.Text;
        //    var iconPath = DataIconPath.Text;
        //    Random random = new Random();
        //    MenuApplication.GetRender<ApplyViewRender>().CreateItem(new ApplyData() { Name = name, IconPath = iconPath, Path = "", Size = random.Next(1, 2) });

        //    DispositionManager.Save();
        //}


        /// <summary>
        /// 初始化应用图标
        /// </summary>
        private void ApplyView_SizeChanged(object sender, RoutedEventArgs e)
        {
            #region 应用列表
            ApplyView_Scroll.Height = this.ActualHeight - 100;

            var size = ApplyElement._sideLength;
            var manger = ApplyElement._margin;

            //获取二维数据的上限
            int ylength = Convert.ToInt32(ApplyView.ActualHeight) / (size + manger);
            int xlength = Convert.ToInt32(ApplyView.ActualWidth) / (size + manger);

            int[][] arr = new int[ylength][];
            for (int i = 0; i < ylength; i++)
            {
                arr[i] = new int[xlength];
            }

            var render = MenuApplication.GetRender<ApplyViewRender>() as ApplyViewRender;
            render.GenerateMatrixArr = arr;
            render.Show();
            #endregion
        }


    }
}
